/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
 *
 */
import { formatTime, Project } from '@ohos/hvigor';
import { AbstractProjectPlugin } from '../plugin/common/abstract-project-plugin.js';
import { BuildInfo } from '../tasks/build-info/build-info.js';
import { Clean } from '../tasks/common/clean.js';
import { TaskNames } from '../tasks/common/task-names.js';
import { CoverageCollect } from '../tasks/coverageCollect/coverageCollect.js';
import { DuplicateDependencyCheck } from '../tasks/duplicate-dependency-check.js';
import { GeneratePackRes } from '../tasks/generate-pack-res.js';
import { AssembleApp } from '../tasks/hook/assemble/assemble-app.js';
import { MakeProjectPackInfo } from '../tasks/make-project-pack-info.js';
import { PackageApp } from '../tasks/package-app.js';
import { PreBuildApp } from '../tasks/pre-build-app.js';
import { ProjectTaskService } from '../tasks/service/project-task-service.js';
import { SignApp } from '../tasks/sign-app.js';
import { SyncProject } from '../tasks/sync/sync-project.js';
import { ProcessProjectPrivacyProfile } from '../tasks/process-project-privacy-profile.js';
import { OhosLogger } from './log/ohos-logger.js';

import SyncTask = TaskNames.SyncTask;


const log = OhosLogger.getLogger('TaskInitialization');

export class ProjectTaskInitializer {
  static initialize(plugin: AbstractProjectPlugin, isFa: boolean) {
    const start: [number, number] = process.hrtime();
    const project = plugin._project;
    const service: ProjectTaskService = plugin.getTaskService()!;

    project.registry(new AssembleApp(project, service));

    project.registry(new Clean(project, service));
    project.registry(new CoverageCollect(project, service));
    project.registry(new SyncProject(project, SyncTask.syncTaskName(project.getName())));
    this.taskInitialize(project, service);
    log.debug(`Project task initialization takes ${formatTime(process.hrtime(start))}`);
  }

  private static taskInitialize(project: Project, service: ProjectTaskService) {
    project.registry(new SignApp(project, service));
    project.registry(new PackageApp(project, service));
    project.registry(new ProcessProjectPrivacyProfile(project, service));
    project.registry(new GeneratePackRes(project, service));
    project.registry(new PreBuildApp(project, service));
    project.registry(new DuplicateDependencyCheck(project, service));
    project.registry(new MakeProjectPackInfo(project, service));
    project.registry(new BuildInfo(project));
  }
}
